(function () {
	 /**
	 * 异步json获取
	 * @param {String} url 接口地址
	 * @param {Object} param 发送数据
	 * @param {Function} [success] 成功回调
	 * @param {Function} [error] 错误回调
	 */
var $modal = $('#pop-modal');
//var iGoodsId = parseInt(page.url.get('id'));
var iGoodsId = 671;
var pageLimit = 3; //热推读取条数
	 
	 getPageData({
	 	goodsId:iGoodsId
	 });
	 
	 function getPageData (Filter)
	 {
	 	
	 	var Filter = Filter;
	 	//获取店铺信息
	 	getJson(Domain+'/ec/goods/doFindGoods.do', {
	 	goodsId:iGoodsId
	 	}, function (res) {
		  if(!res.success){
	
		    $('.am-modal-bd').text(res.errorMessage);
				$modal.modal();
				setTimeout(function () {
					$modal.modal('close');
				},iWiating);

		  }
		  else{

		  	var shopDatas = res;
		  	//获取求购热门列表
			 getHotQglist ({
			 	goodsId:iGoodsId
			 });
			 function getHotQglist (Filter)
			 {

			 	var Filter = Filter;
			 		
			 		if(!Filter.page&&!Filter.pageSize)
			 		{
			 			Filter.page = page.page;
			 			Filter.pageSize = page.pageSize;
			 			Filter.limit = pageLimit;	
			 		}
			 		
			 	getJson(Domain+'/ec/goods/doFindSameCatGoodsList.do', Filter, function (res) {

				  if(!res.success){
			
				    $('.am-modal-bd').text(res.errorMessage);
						$modal.modal();
						setTimeout(function () {
							$modal.modal('close');
						},iWiating);
						return;
				  }
				  else{

			  	 	  page.nowPage = res.data.pageId;
		      		  page.pageCount = res.data.pageCount;
		      		  
		      		  console.log(res);

		      		  if(page.pageCount<=1)
		      		  {
		      		  	$('.page').remove(); //不满2页 删掉分页元素
		      		  }

		      		  if(!res.data.length){
				        $('.page').remove();
				        $('#listbody').append('<li class="empty_div">没有相关的商品哦~</li>');
				      }

				     $('#listbody').empty();

					 shopDatas.goodsList = res.data;
					 console.log(shopDatas);
					 renderTmp('#details', 'detailstpl',shopDatas);
			 		 lazyLoad.refresh(true);
				  }

				},function (error) {

					$('.am-modal-bd').text(language.ajaxFailed);
									$modal.modal();
								setTimeout(function () {
									$modal.modal('close');
								},iWiating);
				})

			 }

			 //右侧分页(下翻)
			 $('.am-icon-angle-down').on('click',function () {

			 	$('.am-icon-angle-up').removeClass('no-page');

			 	if(page.nowPage>=page.pageCount)
			 	{
			 		$(this).addClass('no-page');
					return;
			 	}
			 	
				getHotQglist ({
					goodsId:iGoodsId,
					page:page.nowPage+1
					});
			 });

			 //右侧分页(上翻)
			 $('.am-icon-angle-up').on('click',function () {

			 	$('.am-icon-angle-down').removeClass('no-page');

			 	if(page.nowPage<=page.pageCount)
			 	{
			 		$(this).addClass('no-page');
					return;
			 	}
			 	
				getHotQglist ({
					goodsId:iGoodsId,
					page:page.nowPage-1
					});
			 });

			
	  	 	
		  }
		})
	 }

	 
	

})();